package zust.study.thread;

/**
 * @author senselyan
 * @date 2018/6/12 17:31
 */
public class JoinDemo {
    public static void main(String[] args) {
        Thread previousThread = Thread.currentThread();
        for (int i = 1; i <= 3; i++) {
            Thread curThread = new JoinThread(previousThread, "thread_" + i);
            curThread.start();
            previousThread = curThread;
        }
    }

    static class JoinThread extends Thread {
        private Thread thread;

        public JoinThread(Thread thread ,String name) {
            this.setName(name);
            this.thread = thread;
            System.out.println("this is the chshihua  ---------- " + thread.getName());
        }

        @Override
        public void run() {
            try {
                thread.join();
                System.out.println(thread.getName() + " terminated.");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
